package springstudy;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import springstudy.condition.ConditionalOnSystemProperty;

/**
 * 自定义编程形式的条件装配 {@link springstudy.condition.OnSystemPropertyCondition}
 * @Author acy
 * @Date 2019/04/24
 */
public class ConditionalOnSystemPropertyBootstrap {

	@Bean
	@ConditionalOnSystemProperty(name = "user.name",value = "acy")
	public String helloWorld(){
		return "hello world szh";
	}
	public static void main(String[] args) {
		ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(ConditionalOnSystemPropertyBootstrap.class)
				.web(WebApplicationType.NONE)
				.run(args);
		String helloWorld = applicationContext.getBean("helloWorld", String.class);
		System.out.println("helloWorld Bean "+helloWorld);
		//关闭上下文
		applicationContext.close();
	}
}
